package com.gti.mobilsafe;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class Setup2Activity extends SetupBaseActivity {

	private LinearLayout rl;
	private TelephonyManager tm;
	private SharedPreferences sp;
	private ImageView iv;
	@Override
	public void setView() {
		setContentView(R.layout.setup2);
        rl = (LinearLayout) findViewById(R.id.bind_sim_rel);
        tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        sp = getSharedPreferences("config",MODE_PRIVATE);
        iv = (ImageView) findViewById(R.id.iv_setup2_simbind);
        
       
        rl.setOnClickListener(new OnClickListener() {
        	 
        	
			@Override
			public void onClick(View v) {
				
				Editor editor = sp.edit();
				if(isSimBind()){
	             	iv.setImageResource(R.drawable.btn_check_buttonless_on);
	             	editor.putString("sim", "");
	             }else{
	             	iv.setImageResource(R.drawable.btn_close_normal);
	             	String sim  = tm.getLine1Number();
	             	editor.putString("sim", sim);
	             }
				editor.commit();
				
				
				
			}
		});
	}
	private boolean isSimBind(){
		String sim = sp.getString("sim", "");
		return !TextUtils.isEmpty(sim);
	}

	@Override
	public void findView() {
		

	}

	@Override
	public void showPre() {
		loadActivity(Setup1Activity.class);
		finish();

	}

	@Override
	public void showNext() {
		loadActivity(Setup3Activity.class);
		finish();

	}

}
